#ifndef BUBBLESORT_H_INCLUDED
#define BUBBLESORT_H_INCLUDED

/*
    This is a self implemented version of the classic bubble sort algo.
    It takes a (starting)pointer to an array of pointers and sorts this array.
*/

template <class T>
class BubbleSort {
    private:
        static inline void sortMove(T** pointerToTheArrayOfPointers, unsigned int i) {
            T* temp = pointerToTheArrayOfPointers[i];
            pointerToTheArrayOfPointers[i]=pointerToTheArrayOfPointers[i-1];
            pointerToTheArrayOfPointers[i-1]=temp;
            if ((--i) && (*(pointerToTheArrayOfPointers[i]) < *(pointerToTheArrayOfPointers[i-1])))
                sortMove(pointerToTheArrayOfPointers, i);
        };
        // help method for bubble sort
    public:
        static inline void sort(T** pointerToTheArrayOfPointers, const unsigned int& arraySize) {
            for (unsigned int i=1; i<arraySize; ++i) {
                if(*(pointerToTheArrayOfPointers[i]) < *(pointerToTheArrayOfPointers[i-1]))
                    sortMove(pointerToTheArrayOfPointers, i);
            }
        };
        // main sort method
};

#endif // BUBBLESORT_H_INCLUDED
